package com.longchat.service.impl.weixin;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.springframework.http.converter.json.GsonBuilderUtils;
import org.springframework.stereotype.Service;

import com.longchat.dto.award.WeixinUserInfo;
import com.longchat.dto.system.WeixinProperties;
import com.longchat.service.inter.weixin.IWechatService;
import com.longchat.utils.GsonUtils;
import com.longchat.utils.WeiXinUrl;
import com.longchat.utils.httpUtil.WebUtils;

@Service
public class WechatService implements IWechatService{
	private static final Logger logger = org.slf4j.LoggerFactory.getLogger(WechatService.class);
	@Resource
	private WeixinProperties weixinProp;
	
	@Override
	public  String getOpenId(String code) {
		String url = String.format(WeiXinUrl.GET_OPEINID,weixinProp.getAppid(), weixinProp.getSecret(),code);
		String result = WebUtils.get(url,null);
		logger.info("微信获取openid,，返回result：{}",result);
		Map<String,String> results = GsonUtils.gsonToMaps(result);
		return results.get("openid");
	}

	@Override
	public WeixinUserInfo getUserInfo(String openid) {
		// TODO Auto-generated method stub
		return null;
	}

	
	
}
